//const baseUrl = "http://192.168.0.119:8085/canteen-api/api/"
//const baseUrl = "http://192.168.0.110:8081/canteen-api/api/"
const baseUrl = "https://api.canteen.jiangshan.hzzhixun.cn/canteen-api/api/"
/*
 * 通用POST请求封装
 * @param url {String} 相对地址
 * @param data {Array} 请求数据
 * @param success {Function} 成功后的回调
 * @param fail {Function} 失败后的回调
 * @return void
 */
const postFetch = (url, data, success, fail) => {
  wx.request({
    url: baseUrl + url,
    method: 'post',
    data: data,
    header: {
      token: wx.getStorageSync('userToken'),
      userId: wx.getStorageSync('userId'),
    },
    success: function(res) {
      if (success) {
        if (res.data.code !== 0) {
          wx.showToast({
            title: res.data.msg,
            icon: "none"
          })
         return
        }else{
          success(res.data);
        }
      }
    }
  })
};
const putFetch = (url, data, success, fail) => {
  wx.request({
    url: baseUrl + url,
    method: 'put',
    data: data,
    header: {
      'content-type': 'application/x-www-form-urlencoded',
      userId: wx.getStorageSync('userId'),
      token: wx.getStorageSync('userToken'),
    },
    success: function(res) {
        if (res.data.data) {
          success(res.data.data||{});
        }
    }
  })
};
const getFetch = (url, data, success, fail) => {
  wx.request({
    url: baseUrl + url,
    method: 'get',
    data: data,
    header: {
      'content-type': 'application/x-www-form-urlencoded',
      userId: wx.getStorageSync('userId'),
      token: wx.getStorageSync('userToken'),
    },
    success: function(res) {
      if (success) {
          success(res.data.data||{});
      }
    }
  })
};
/*
 * 通用POST请求封装
 * @param url {String} 相对地址
 * @param data {Array} 请求数据
 * @param success {Function} 成功后的回调
 * @param fail {Function} 失败后的回调
 * @return void
 */
const postJsonFetch = (url, data, success, fail) => {
  wx.request({
    url: baseUrl + url,
    method: 'POST',
    data: data,
    header: {
      userId: wx.getStorageSync('userId'),
      'content-type': 'application/json',
      token: wx.getStorageSync('userToken'),
    },
    success: function(res) {
      if (success) {
          success(res.data.data||{});
      }
    }
  })
};
const stockorderHome = (data, success, fail) => {
  getFetch('stockorder/getChedOrder', Object.assign(data), success, fail);
}
const personneldict = (data, success, fail) => {
  getFetch('personneldict/page', Object.assign(data), success, fail);
}
const getSupplier = (data, success, fail) => {
  getFetch('supplier/page', Object.assign(data), success, fail);
}

const supplierFoodId = (data, success, fail) => {
  getFetch('food/supplierFoodId', Object.assign(data), success, fail);
}
const getOrderMx = (data, success, fail) => {
  getFetch('batchorder/getOrderMx', Object.assign(data), success, fail);
}
const temporaryordersaveOrder = (data, success, fail) => {
  postFetch('temporaryorder/saveOrder', Object.assign(data), success, fail);
}
const getSignIN = (data, success, fail) => {
  postFetch('login', Object.assign(data), success, fail);
}
const temporaryorderupdeteOrder = (data, success, fail) => {
  postFetch('temporaryorder/updeteOrder', Object.assign(data), success, fail);
}
const financegetBatchOrder = (data, success, fail) => {
  postFetch('finance/getBatchOrder', Object.assign(data), success, fail);
}
const financegetBatchOrderMx = (data, success, fail) => {
  postFetch('finance/getBatchOrderMx', Object.assign(data), success, fail);
}
//订单生成接口
const saveOrder = (data, success, fail) => {
  postJsonFetch('stockorder/saveOrder', Object.assign(data), success, fail);
}

const pageAdmin = (data, success, fail) => {
  getFetch('stockorder/pageAdmin', Object.assign(data), success, fail);
}
const getTemOrdermx = (data, success, fail) => {
  getFetch('temporaryorder/getTemOrder', Object.assign(data), success, fail);
}
const pageAdminUpdate = (data, success, fail) => {
  postFetch('stockorder/pageAdminUpdate', Object.assign(data), success, fail);
}
const selectFinancemx = (data, success, fail) => {
  postFetch('finance/selectFinancemx', Object.assign(data), success, fail);
}
const saveFood = (data, success, fail) => {
  postFetch('temporaryordermx/saveFood', Object.assign(data), success, fail);
}
// const saveFood = (data, success, fail) => {
//   postFetch('api/smallcanteenpurchasemx/update', Object.assign(data), success, fail);
// }
// const saveFood = (data, success, fail) => {
//   postFetch('api/smallcanteenpurchasemx/save', Object.assign(data), success, fail);
// }
const getWareHouse = (data, success, fail) => {
  putFetch('stockordermx/updateUnit', Object.assign(data), success, fail);
}

const getPrice = (data, success, fail) => {
  postJsonFetch('stockordermx/updateUnit', Object.assign(data), success, fail);
}
const TakePhoto = (data, success, fail) => {
  postJsonFetch('stockordermx/updatePhoto', Object.assign(data), success, fail);
}

const selecSupplierOd = (data, success, fail) => {
  getFetch('stockorder/selecSupplierOd', Object.assign(data), success, fail);
}
const getBatchOrdermx = (data, success, fail) => {
  getFetch('batchordermx/getBatchOrdermx', Object.assign(data), success, fail);
}
const selecSupplierOrder = (data, success, fail) => {
  getFetch('stockorder/selecSupplierOrder1', Object.assign(data), success, fail);
}
const getImportAmount = (data, success, fail) => {
  getFetch('importamount/getImportAmount', Object.assign(data), success, fail);
}

const wareHouseHome = (data, success, fail) => {
  getFetch('stockorder/pagesTorehouseClerk', Object.assign(data), success, fail);
}
const getSupplierName = (data, success, fail) => {
  getFetch('food/getSupplierName', Object.assign(data), success, fail);
}
const getOrderDetails = (data, success, fail) => {
  getFetch('stockordermx/details', Object.assign(data), success, fail);
}
const auxiliarymateri = (data, success, fail) => {
  getFetch('auxiliarymateri/page', Object.assign(data), success, fail);
}
const auxiliarymateriAdmin = (data, success, fail) => {
  getFetch('auxiliarymateri/pageAdmin', Object.assign(data), success, fail);
}
const selecSupplierMateriOrder = (data, success, fail) => {
  getFetch('auxiliarymateri/selecSupplierMateriOrder', Object.assign(data), success, fail);
}
const uploadImg = (data, success, fail) => {
  postFetch('oss/upload', Object.assign(data), success, fail);
}
const selecSupplierOrder1 = (data, success, fail) => {
  getFetch('auxiliarymateri/selecSupplierOrder1', Object.assign(data), success, fail);
}
const auxiliarymaterialsmxDetails = (data, success, fail) => {
  getFetch('auxiliarymaterialsmx/details', Object.assign(data), success, fail);
}
const auxiliarymateriPageAdmin = (data, success, fail) => {
  getFetch('auxiliarymateri/pageAdmin', Object.assign(data), success, fail);
}
const smallcanteenpurchase = (data, success, fail) => {
  getFetch('smallcanteenpurchase/page', Object.assign(data), success, fail);
}
const smallcanteenpurchasepageAdmin = (data, success, fail) => {
  getFetch('smallcanteenpurchase/pageAdmin', Object.assign(data), success, fail);
}
const smallcanteenpurchasemxdetails = (data, success, fail) => {
  getFetch('smallcanteenpurchasemx/details', Object.assign(data), success, fail);
}
const selecSupplierSmallOrder = (data, success, fail) => {
  getFetch('smallcanteenpurchase/selecSupplierSmallOrder', Object.assign(data), success, fail);
}
const smallcanteenpurchasemxOrder1 = (data, success, fail) => {
  getFetch('smallcanteenpurchasemx/selecSupplierCanteenOrder1', Object.assign(data), success, fail);
}
const pagesTorehouseClerk = (data, success, fail) => {
  getFetch('smallcanteenpurchase/pagesTorehouseClerk', Object.assign(data), success, fail);
}
const selectFoodmx = (data, success, fail) => {
  getFetch('foodmx/selectAllFoodmx', Object.assign(data), success, fail);
}
const slectPages = (data, success, fail) => {
  getFetch('marketmx/slectPages', Object.assign(data), success, fail);
}
const collarpageAdmin = (data, success, fail) => {
  getFetch('collar/pageAdmin', Object.assign(data), success, fail);
}

const slectPagesfood = (data, success, fail) => {
  getFetch('food/page', Object.assign(data), success, fail);
}
const collarhome = (data, success, fail) => {
  getFetch('collar/page', Object.assign(data), success, fail);
}
const collarmxdetails = (data, success, fail) => {
  getFetch('collarmx/details', Object.assign(data), success, fail);
}
const collarTorehouseClerk = (data, success, fail) => {
  getFetch('collar/pagesTorehouseClerk', Object.assign(data), success, fail);
}
const selectDetails = (data, success, fail) => {
  getFetch('marketmx/selectDetails', Object.assign(data), success, fail);
}
const slectCompare = (data, success, fail) => {
  getFetch('marketmx/slectCompare', Object.assign(data), success, fail);
}
const getOrder = (data, success, fail) => {
  getFetch('batchorder/getOrder', Object.assign(data), success, fail);
}
const updateOrder = (data, success, fail) => {
  postFetch('stockorder/updateOrder', Object.assign(data), success, fail);
}
const selectSupplierFinance = (data, success, fail) => {
  postFetch('finance/selectSupplierFinance', Object.assign(data), success, fail);
}
const selectTotalFinance = (data, success, fail) => {
  postFetch('finance/selectTotalFinance', Object.assign(data), success, fail);
}
const saveCollarOrder = (data, success, fail) => {
  postFetch('collar/saveCollarOrder', Object.assign(data), success, fail);
}
const updateNum = (data, success, fail) => {
  postFetch('stockorder/updateNum', Object.assign(data), success, fail);
}
const updateFood = (data, success, fail) => {
  postFetch('temporaryordermx/updateFood', Object.assign(data), success, fail);
}
const saveAuxiliaryOrder = (data, success, fail) => {
  postFetch('auxiliarymateri/saveAuxiliaryOrder', Object.assign(data), success, fail);
}
const deleteFood = (data, success, fail) => {
  postFetch('temporaryordermx/deleteFood', Object.assign(data), success, fail);
}
const temporaryordermxgetTemOrdermx = (data, success, fail) => {
  postFetch('temporaryordermx/getTemOrdermx', Object.assign(data), success, fail);
}
const pageAdminUpdate2 = (data, success, fail) => {
  postFetch('auxiliarymateri/pageAdminUpdate', Object.assign(data), success, fail);
}
const updateUnit = (data, success, fail) => {
  postFetch('auxiliarymaterialsmx/updateUnit', Object.assign(data), success, fail);
}
const updatePhoto = (data, success, fail) => {
  postFetch('auxiliarymaterialsmx/updatePhoto', Object.assign(data), success, fail);
}
const smallcanteenpurchasepageAdminUpdate = (data, success, fail) => {
  postFetch('smallcanteenpurchase/pageAdminUpdate', Object.assign(data), success, fail);
}
const smallcanteenupdateUnit = (data, success, fail) => {
  postFetch('smallcanteenpurchasemx/updateUnit', Object.assign(data), success, fail);
}
const smallsaveAuxiliaryOrder = (data, success, fail) => {
  postFetch('smallcanteenpurchase/saveAuxiliaryOrder', Object.assign(data), success, fail);
}
const smallcaupdatePhoto = (data, success, fail) => {
  postFetch('smallcanteenpurchasemx/updatePhoto', Object.assign(data), success, fail);
}
const savaUnitPrice = (data, success, fail) => {
  postFetch('marketmx/savaUnitPrice', Object.assign(data), success, fail);
}
const collarpageAdminUpdate = (data, success, fail) => {
  postFetch('collar/pageAdminUpdate', Object.assign(data), success, fail);
}
const collarmxupdatePhoto = (data, success, fail) => {
  postFetch('collarmx/updatePhoto', Object.assign(data), success, fail);
}
const updateExamine = (data, success, fail) => {
  postFetch('batchorder/updateExamine', Object.assign(data), success, fail);
}
const selectFinance = (data, success, fail) => {
  postFetch('finance/selectFinance', Object.assign(data), success, fail);
}
const updateSupplierStutas = (data, success, fail) => {
  postFetch('stockorder/UpdateSupplierStutas', Object.assign(data), success, fail);
}
const financeAdminUpdate = (data, success, fail) => {
  postFetch('finance/adminUpdate', Object.assign(data), success, fail);
}
const auxiliarymateriUpdateSupplierOrder = (data, success, fail) => {
  postFetch('auxiliarymateri/UpdateSupplierOrder', Object.assign(data), success, fail);
}
  const smallcanteenpurchaseUpdateSupplierOrder = (data, success, fail) => {
  postFetch('smallcanteenpurchase/UpdateSupplierOrder', Object.assign(data), success, fail);
}
const selectFinanceStatement = (data, success, fail) => {
  postFetch('finance/selectFinanceStatement', Object.assign(data), success, fail);
}
const batchOrderList = (data, success, fail) => {
  postFetch('batchorder/batchOrderList', Object.assign(data), success, fail);
}
const batchorderupdatePhoto = (data, success, fail) => {
  postFetch('batchorder/updatePhoto', Object.assign(data), success, fail);
}

module.exports = {
  getSupplierName,
  baseUrl,
  postFetch: postFetch,
  postJsonFetch: postJsonFetch,
  stockorderHome,
  getSupplier,
  saveOrder,
  getSignIN,
  pageAdminUpdate,
  getWareHouse,
  getPrice,
  supplierFoodId ,
  pageAdmin,
  TakePhoto,
  selecSupplierOd,
  selecSupplierOrder,
  wareHouseHome,
  getOrderDetails,
  uploadImg,
  updateOrder,
  updateNum,
  auxiliarymateri,
  auxiliarymateriAdmin,
  pageAdminUpdate2,
  selecSupplierMateriOrder,
  selecSupplierOrder1,
  updateUnit,
  auxiliarymaterialsmxDetails,
  saveAuxiliaryOrder,
  auxiliarymateriPageAdmin,
  updatePhoto,
  smallcanteenpurchase,
  smallcanteenpurchasepageAdmin,
  smallcanteenpurchasemxdetails,
  selecSupplierSmallOrder,
  smallcanteenpurchasepageAdminUpdate,
  smallcanteenpurchasemxOrder1,
  smallcanteenupdateUnit,
  pagesTorehouseClerk,
  smallsaveAuxiliaryOrder,
  smallcaupdatePhoto,
  selectFoodmx,
  slectPages,
  slectPagesfood,
  collarpageAdmin,
  collarmxdetails,
  saveCollarOrder,
  collarTorehouseClerk,
  collarhome,
  savaUnitPrice,
  selectDetails,
  collarpageAdminUpdate,
  collarmxupdatePhoto,
  selectTotalFinance,
  selectSupplierFinance,
  selectFinance,
  updateSupplierStutas,
  selectFinancemx,
  financeAdminUpdate,
  auxiliarymateriUpdateSupplierOrder,
  smallcanteenpurchaseUpdateSupplierOrder,
  selectFinanceStatement,
  slectCompare,
  batchOrderList,
  getOrder,
  getImportAmount,
  updateExamine,
  getOrderMx,
  batchorderupdatePhoto,
  getBatchOrdermx,
  getTemOrdermx,
  saveFood,
  updateFood,
  deleteFood,
  temporaryordermxgetTemOrdermx,
  temporaryorderupdeteOrder,
  temporaryordersaveOrder,
  financegetBatchOrder,
  financegetBatchOrderMx,
  personneldict
}
